//for_each()函数的模拟实现
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
template<typename T>
void fun1(const T &str){
    cout<<str<<" ";
}
template<typename T>
class person{
public:
    void operator()(const T &str){
        cout<<str<<" ";
    }
};
template<typename T1,typename T2>
void foreach(const T1 first,const T1 last,T2 pfun){
    for(auto it=first;it!=last;it++){
        pfun(*it);
    }
}
int main()
{
    vector<int> a {1,2,3,4,5,6,7,8};
    list<string> b {"张阿生那你","askd","kajsgd"};
    foreach(a.begin(),a.end(),fun1<int>);
    cout<<endl;
    foreach(a.begin(),a.end(),person<int>());
    cout<<endl;
    for_each(a.begin(),a.end(),person<int>());
    cout<<endl;
    foreach(b.begin(),b.end(),fun1<string>);
    cout<<endl;
    for_each(b.begin(),b.end(),fun1<string>);
    return 0;
}